﻿@model PotentialRentals.Models.Rental

<script type="text/javascript">
    function UpdateCreateAddress() {
        if ($("#create-rental-content input[name='RentalConfirm']:checked").length <= 0) {
            alert("You must select an Address to save for your Rental");
            return false;
        }

        //Loop through each Result, find the one with the radio selected and move the values to the
        $("table#Rental-Result").each(function () {
            //$("#Address_Name").val($("#AddressName").val());
            if ($(this).find("input[name='RentalConfirm']").is(":checked")) {
                $(this).find("input:hidden").each(function () {
                    switch ($(this).attr("name")) {
                        case "StreetAddress":
                            $("#Address_Street").val($(this).val());
                            break;
                        case "City":
                            $("#Address_City").val($(this).val());
                            break;
                        case "StateId":
                            $("#Address_State_StateId").val($(this).val());
                            break;
                        case "Zip":
                            $("#Address_Zip").val($(this).val());
                            break;
                        case "Latitude":
                            $("#Address_Lat").val($(this).val());
                            break;
                        case "Longitude":
                            $("#Address_Lng").val($(this).val());
                            break;
                    }
                });
            }
        });
    }
</script>

@if (TempData["message"] != null)
{
    @Html.Raw(TempData["message"].ToString())
}

<h3 style="margin-bottom:0;padding-bottom:0;">Your Entry:</h3>
<div id="rental">
    <table cellpadding="3" cellspacing="0" border="0" width="100%">
        <tr>
            <td>
                <span class="Location">@Model.Address.Street</span><br />
                <span class="CityState">@Model.Address.City, @ViewBag.StateAbbr</span><br />
                @if(Model.Phone != null) 
                {
                    <span class="Phone">@Model.Phone</span><br />
                }
                @if(Model.Email != null) 
                {
                    <span class="Email">@Html.Raw(String.Format("<a href='mailto:{0}'>{0}</a>", Model.Email))</span><br />
                }
                <span class="Bedbath">@String.Format("{0}br/{1}ba - ${2}", Model.Bedrooms, Model.Bathrooms, Model.Rent)</span>

                <h5 style="color:#303F55">Rental Amenities:</h5>

                @foreach (var amenity in ViewBag.RentalAmenityList as MultiSelectList)
                {
                    if (amenity.Selected)
                    {
                        <input type="checkbox" name="RentalAmenityList" value="@amenity.Value" checked="checked" disabled="disabled" /> @amenity.Text<br />
                    }
                }
            </td>
        </tr>
    </table>
</div>

<h3 style="margin-bottom:0;padding-bottom:0;">Select One:</h3>

<hr />
@foreach (var address in ViewBag.AddressResults)
{
    <table id="Rental-Result" cellpadding="3" cellspacing="0" border="1">
        <tr>
            <td padding="0" style="padding:0">
                <input type="radio" name="RentalConfirm" />
            </td>
            <td>
                @if (address.Name != null)
                {
                    @address.Name<br />
                }
                @address.Street<br /> 
                @address.City, @address.State.Abbr @address.Zip<br />
                    <input type="hidden" name="StreetAddress" value="@address.Street" />
                    <input type="hidden" name="City" value="@address.City" />
                    <input type="hidden" name="StateId" value="@address.State.StateId" />
                    <input type="hidden" name="Zip" value="@address.Zip" />
                <span id="Latlng">@String.Format("{0:0#.####}", address.Lat) / @String.Format("{0:0#.####}", address.Lng)</span><br />
                    <input type="hidden" name="Latitude" value="@address.Lat" />
                    <input type="hidden" name="Longitude" value="@address.Lng" />
                @if (address.AddressId > 0)
                {
                    <span>local</span>
                }
            </td>
        </tr>
    </table>
    <hr />
}

@using (Ajax.BeginForm("Create", null, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "create-rental-content", OnSuccess = "toggleContentLeft();refreshLists();" }, new { id = "ConfirmAddress-Form" }))
{
    @Html.ValidationSummary(true)

        <h5>Address Amenities:</h5>
        <div class="editor-field">
            @foreach (var amenity in ViewBag.AddressAmenityList as MultiSelectList)
            {
                <input type="checkbox" name="AddressAmenityList" value="@amenity.Value" /> @amenity.Text<br />
            }
        </div>
    
        @Html.HiddenFor(model => model.Address.Name)
        @Html.HiddenFor(model => model.Address.Street)
        @Html.HiddenFor(model => model.Address.City)
        @Html.HiddenFor(model => model.Address.State.StateId)
        @Html.HiddenFor(model => model.Address.Zip)
        @Html.HiddenFor(model => model.Address.Lat)
        @Html.HiddenFor(model => model.Address.Lng)
        @Html.HiddenFor(model => model.Type.RentTypeId)
        @Html.HiddenFor(model => model.Phone)
        @Html.HiddenFor(model => model.Email)
        @Html.HiddenFor(model => model.Rent)
        @Html.HiddenFor(model => model.Deposit)
        @Html.HiddenFor(model => model.Bedrooms)
        @Html.HiddenFor(model => model.Bathrooms)
        
        foreach (var amentity in ViewBag.RentalAmenityList as MultiSelectList)
        {
            if (amentity.Selected)
            {
                <input type="hidden" name="RentalAmenityList" value="@amentity.Value" />
            }
        }

    <p>
        <input type="submit" value="Create" onclick="return UpdateCreateAddress()" /> | @Ajax.ActionLink("Cancel", "Create", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "create-rental-content" })
    </p>
}